 'API function to enable/disable the Excel Window
Private Declare Function FindWindowA Lib "user32" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
 Private Declare Function EnableWindow Lib "user32" _
(ByVal hwnd As Long, ByVal bEnable As Long) As Long
Private Declare Function SetWindowPos Lib "user32" ( _
ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _
ByVal X As Long, ByVal Y As Long, ByVal cx As Long, _
ByVal cy As Long, ByVal wFlags As Long) As Long
 
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const FLAGS As Long = SWP_NOMOVE Or SWP_NOSIZE
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private mlHWnd As Long
Private mbDragDrop As Boolean
Private FormHWnd As Long
Private Sub cmdNotTop_Click()
    SetWindowPos FormHWnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS
End Sub
Private Sub cmdTop_Click()
    SetWindowPos FormHWnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS
End Sub
Private Sub btnOK_Click()
    Application.CellDragAndDrop = mbDragDrop
    Call cmdNotTop_Click
    Unload Me
End Sub

Private Sub Label16_Click()

End Sub

Private Sub Label16_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
UserForm3.Caption = "date"
UserForm3.Show
End Sub

Private Sub optHideTitleBar_Click()
Dim B As Boolean
B = ShowTitleBar(UF:=Me, HideTitle:=True)
B = IsTitleBarVisible(UF:=Me)
If B = True Then
    Me.lblCaptionVisible.Caption = ""
Else
    Me.lblCaptionVisible.Caption = ""
End If
End Sub
Private Sub optEnableCloseButton_Click()
Dim B As Boolean
B = EnableCloseButton(UF:=Me, Disable:=False)
B = IsCloseButtonEnabled(UF:=Me)
If B = True Then
    Me.lblCloseEnabled.Caption = "Button Enabled"
Else
    Me.lblCloseEnabled.Caption = "Button Disabled"
End If
End Sub
Private Sub CheckBox1_Click()
If CheckBox1 = True Then
TextBox1.Locked = False
TextBox1 = Range("A1").Value
CommandButton1.Visible = True
ListBox1.Visible = False
CommandButton3.Visible = False
Labl_A.Visible = True
Label6.Visible = True
Label7.Visible = True
Label8.Visible = True
Label9.Visible = True
Label10.Visible = True
Label11.Visible = True
Label12.Visible = True
Label13.Visible = True
Label14.Visible = True
Label15.Visible = True
Frame1.Visible = True
Frame2.Visible = True
Frame3.Visible = True
Frame4.Visible = True
Frame5.Visible = True
Frame6.Visible = True
Frame7.Visible = True
Frame8.Visible = True
Frame9.Visible = True
Frame10.Visible = True
Frame11.Visible = True
Frame13.Visible = True
Text_A.Visible = True
TextBox1.Visible = True
TextBox2.Visible = True
TextBox3.Visible = True
TextBox5.Visible = True
TextBox6.Visible = True
TextBox7.Visible = True
TextBox8.Visible = True
TextBox9.Visible = True
TextBox10.Visible = True
TextBox11.Visible = True
Text_A.SetFocus
TextBox1 = ""
Text_A = ""
TextBox2 = ""
TextBox3 = ""
TextBox4 = ""
TextBox5 = ""
TextBox6 = ""
TextBox7 = ""
TextBox8 = ""
TextBox9 = ""
TextBox10 = ""
TextBox11 = ""
Else
TextBox1.Locked = False
CommandButton1.Visible = False
ListBox1.Visible = False
CommandButton3.Visible = False
Label6.Visible = False
Label7.Visible = False
Label8.Visible = False
Label9.Visible = False
Label10.Visible = False
Label11.Visible = False
Label12.Visible = False
Label13.Visible = False
Label14.Visible = False
Label15.Visible = False
Frame1.Visible = False
Frame2.Visible = False
Frame3.Visible = False
Frame4.Visible = False
Frame5.Visible = False
Frame6.Visible = False
Frame7.Visible = False
Frame8.Visible = False
Frame9.Visible = False
Frame10.Visible = False
TextBox1.Visible = False
TextBox2.Visible = False
TextBox3.Visible = False
TextBox5.Visible = False
TextBox6.Visible = False
TextBox7.Visible = False
TextBox8.Visible = False
TextBox9.Visible = False
TextBox10.Visible = False
TextBox11.Visible = False
Exit Sub
End If
End Sub
'================ *** ================
'    
'******* [ maicl2010ye@gmail.com ] *******
' 
'================ *** ================
Private Sub CommandButton1_Click()

'====================================
On Error Resume Next
Application.EnableEvents = False
Application.ScreenUpdating = False
If TextBox1 = "" Or TextBox2 = "" Or TextBox3 = "" Then
MsgBox "  ", vbExclamation, " "
Exit Sub
End If
ex = Sheets("2").Range("a4").End(xlDown).Row
If Application.WorksheetFunction.CountIf(Sheets("2").Range("a4:a" & ex), Text_A.Value) > 0 Then
ans = MsgBox("          ?" & vbCrLf & TextBox5.Text & vbCrLf, vbYesNo)
If ans = vbYes Then
Sheets("2").Select
Cells.Find(What:=Text_A.Text, After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=True _
, SearchFormat:=False).Activate
ir = ActiveCell.Offset(0, 2).Row
Sheets("2").Cells(ir, "c") = Application.WorksheetFunction.Sum(Sheets("2").Range("c" & ir) + TextBox5.Text)
End If
'=====    
Sheets("DATA_FLDO").Select

Call FOTMAT_A

'====          
'===       
Dim RROW As Integer, A As Integer
Dim WS As Worksheet
Dim sh As Worksheet
 Set WS = Sheets("DATA_FLDO")
      RROW = WS.Cells(Rows.Count, 3).End(xlUp).Offset(1, 0).Row
 WS.Cells(RROW, 1).Value = Text_A.Text
WS.Cells(RROW, 2).Value = TextBox1.Text
WS.Cells(RROW, 3).Value = TextBox2.Text
WS.Cells(RROW, 4).Value = TextBox3.Text
WS.Cells(RROW, 6).Value = TextBox5.Text
WS.Cells(RROW, 7).Value = TextBox6.Text
WS.Cells(RROW, 9).Value = TextBox7.Text
WS.Cells(RROW, 11).Value = TextBox8.Text
WS.Cells(RROW, 12).Value = TextBox9.Text
WS.Cells(RROW, 13).Value = TextBox10.Text
WS.Cells(RROW, 14).Value = TextBox11.Text

Call FOTMAT_B

Else
Sheets("DATA_FLDO").Select

Call FOTMAT_A

Application.ScreenUpdating = False
Application.EnableEvents = False
Dim RROW_1 As Integer
Dim WS_1 As Worksheet
Set WS_1 = Sheets("DATA_FLDO")
RROW_1 = WS_1.Cells(Rows.Count, 3).End(xlUp).Offset(1, 0).Row
WS_1.Cells(RROW_1, 1).Value = Text_A.Text
WS_1.Cells(RROW_1, 2).Value = TextBox1.Text
WS_1.Cells(RROW_1, 3).Value = TextBox2.Text
WS_1.Cells(RROW_1, 4).Value = TextBox3.Text
WS_1.Cells(RROW_1, 6).Value = TextBox5.Text
WS_1.Cells(RROW_1, 7).Value = TextBox6.Text
WS_1.Cells(RROW_1, 9).Value = TextBox7.Text
WS_1.Cells(RROW_1, 11).Value = TextBox8.Text
WS_1.Cells(RROW_1, 12).Value = TextBox9.Text
WS_1.Cells(RROW_1, 13).Value = TextBox10.Text
WS_1.Cells(RROW_1, 14).Value = TextBox11.Text
Call FOTMAT_B

Application.ScreenUpdating = True
Application.EnableEvents = True
Application.ScreenUpdating = False
Application.EnableEvents = False
Sheets("").Select
Dim A_1 As Integer
Dim sh1 As Worksheet
Set sh1 = Sheets("2")
A_1 = sh1.Cells(Rows.Count, 3).End(xlUp).Offset(1, 0).Row
sh1.Cells(A_1, 1).Value = Text_A.Text
sh1.Cells(A_1, 2).Value = TextBox1.Text
sh1.Cells(A_1, 5).Value = TextBox3.Text
sh1.Cells(A_1, 6).Value = TextBox2.Text
sh1.Cells(A_1, 8).Value = TextBox5.Text
sh1.Cells(A_1, 9).Value = TextBox8.Text
'sh1.Cells(A_1, 9).Value = TextBox7.Text
'sh1.Cells(A_1, 11).Value = TextBox8.Text
'sh1.Cells(A_1, 12).Value = TextBox9.Text
'sh1.Cells(A_1, 13).Value = TextBox10.Text
'sh1.Cells(A_1, 14).Value = TextBox11.Text

Call FOTMAT_M_DATA
Cells(X, "a").Select
Application.EnableEvents = True
Application.ScreenUpdating = True
Sheets("DATA_FLDO").Select
End If
'==============================================
'===     
Me.Text_A.Value = ""
Me.TextBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
Me.TextBox5.Value = ""
Me.TextBox6.Value = ""
Me.TextBox7.Value = ""
Me.TextBox8.Value = ""
Me.TextBox9.Value = ""
Me.TextBox10.Value = ""
Me.TextBox11.Value = ""
Me.Text_A.SetFocus '      

End Sub
Private Sub CommandButton3_Click()
'===  
Dim A As String
Dim B As Worksheet
Dim Msg As String
Dim ans As Integer
On Error Resume Next
Application.EnableEvents = False
Application.ScreenUpdating = False
Msg = "     "
ans = MsgBox(Msg, vbYesNo)
If ans = vbYes Then
MsgBox "   ", 0, "  "
A = ListBox1.List(ListBox1.ListIndex, 6)
Set MYSH = Sheets("DATA_FLDO")
With MYSH
.Application.Range(A).Activate
.Range(A).Value = TextBox1.Text
.Range(A).Offset(0, 1).Value = TextBox2.Value
.Range(A).Offset(0, 2).Value = TextBox3.Value
.Range(A).Offset(0, 4).Value = TextBox5.Value
.Range(A).Offset(0, 5).Value = TextBox6.Value
.Range(A).Offset(0, 7).Value = TextBox7.Value
.Range(A).Offset(0, 9).Value = TextBox8.Value
.Range(A).Offset(0, 10).Value = TextBox9.Value
.Range(A).Offset(0, 11).Value = TextBox10.Value
.Range(A).Offset(0, 12).Value = TextBox11.Value
'===           
.Range("d5:d2000").Formula = "=IF(A5>0,C5*B5,"") "
.Range("g4:g2000").Formula = "=IF(A5>0;F5*E5;"")"
.Range("i4:i2000").Formula = "=IF(A7>0;H7*C7;"") "
End With
Application.EnableEvents = False
i = Sheets("DATA_FLDO").Range("d2000").End(xlUp).Row
Sheets("DATA_FLDO").Range("d" & i).Select
Selection.EntireRow.Delete
Application.EnableEvents = True
Z = Sheets("DATA_FLDO").Range("d15000").End(xlUp).Row + 1
Cells(Z, d).Select
ss = ActiveCell.Row
Cells(ss, l).EntireRow.Delete
 X = Sheets("DATA_FLDO").Range("d15000").End(xlUp).Row + 1
Cells(X, "l") = " "
Cells(X, "m").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-9]-RC[-6]-RC[-4]-RC[-2])"
Cells(X, "k") = Application.WorksheetFunction.Sum(Range([k5], Cells(X, "k")))
Cells(X, "i") = Application.WorksheetFunction.Sum(Range([i5], Cells(X, "i")))
Cells(X, "g") = Application.WorksheetFunction.Sum(Range([g5], Cells(X, "g")))
Cells(X, "d") = Application.WorksheetFunction.Sum(Range([d5], Cells(X, "d")))
[A1].Select
Range("A" & X & ":m" & X).Select
With Selection
.Font.Size = 22
.Font.Bold = True
.Font.Name = "Traditional Arabic"
.Font.Color = vbBlue
.Interior.Color = &HFFFFC0
.Borders.Weight = xlThick
.Borders.Weight = xlThisWeek
.Borders.Color = vbRed
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
End With
Cells(X, "a").Select
Application.EnableEvents = True
Application.ScreenUpdating = True
Else
Exit Sub
End If
'===    
For C = 1 To 11
Me.Controls("TEXTBOX" & C).Text = ""
Next C
ListBox1.Clear
TextBox4.Text = ""
TextBox4.SetFocus
End Sub
Private Sub Label4_Click()
Me.Hide
End Sub
Private Sub ListBox1_Click()
' ===          6
Dim DADA As String
Dim MYSH As Worksheet
On Error Resume Next
CommandButton3.Visible = True
DADA = ListBox1.List(ListBox1.ListIndex, 6)
Set MYSH = Sheets("DATA_FLDO")
With MYSH
.Application.Range(DADA).Activate
Frame1.TextBox1.Text = .Range(DADA).Text
Frame2.TextBox2.Text = .Range(DADA).Offset(0, 1).Text
Frame3.TextBox3.Text = .Range(DADA).Offset(0, 2).Text
Frame4.TextBox5.Text = .Range(DADA).Offset(0, 4).Text
Frame5.TextBox6.Text = .Range(DADA).Offset(0, 5).Text
Frame6.TextBox7.Text = .Range(DADA).Offset(0, 7).Text
Frame7.TextBox8.Text = .Range(DADA).Offset(0, 9).Text
Frame8.TextBox9.Text = .Range(DADA).Offset(0, 10).Text
Frame9.TextBox10.Text = .Range(DADA).Offset(0, 11).Text
Frame10.TextBox11.Text = .Range(DADA).Offset(0, 12).Text
End With
End Sub
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
'===               
'===  1234
Dim DADA As String
Dim MYSH1 As Worksheet
Dim MYSH2 As Worksheet
Dim PASSWORD As Integer
On Error Resume Next
Application.EnableEvents = False
Application.ScreenUpdating = False
PASSWORD = InputBox("       ", "      ")
If PASSWORD <> "1234" Then ' ===           
MsgBox "  "
Else
If MsgBox(":    " & vbNewLine & "" & vbNewLine & " :  " & TextBox1 _
& vbNewLine & "  ѿ", vbYesNo + vbQuestion, " ") = vbYes Then
A = Application.WorksheetFunction.Match(ListBox1, rng1, 0)
Application.ScreenUpdating = False
MsgBox "     " & ListBox1 & " ", vbInformation, " "
Application.ScreenUpdating = False
DADA = ListBox1.List(ListBox1.ListIndex, 6)
Set MYSH1 = Sheets("DATA_FLDO")
  With MYSH1
    .Application.Range(DADA).Rows.Select
    .Range(DADA).EntireRow.Delete
    Application.ScreenUpdating = True
  End With
  
 End If
 End If
Application.EnableEvents = False
i = Sheets("DATA_FLDO").Range("d2000").End(xlUp).Row
Sheets("DATA_FLDO").Range("d" & i).Select
Selection.EntireRow.Delete
Z = Sheets("DATA_FLDO").Range("d15000").End(xlUp).Row + 1
Cells(Z, d).Select
ss = ActiveCell.Row
Cells(ss, l).EntireRow.Delete
Dim X As Integer
 X = Sheets("DATA_FLDO").Range("d5000").End(xlUp).Row + 1
Cells(X, "l") = " "
Cells(X, "m").Select
ActiveCell.FormulaR1C1 = "=SUM(RC[-9]-RC[-6]-RC[-4]-RC[-2])"
Cells(X, "k") = Application.WorksheetFunction.Sum(Range([k5], Cells(X, "k")))
Cells(X, "i") = Application.WorksheetFunction.Sum(Range([i5], Cells(X, "i")))
Cells(X, "g") = Application.WorksheetFunction.Sum(Range([g5], Cells(X, "g")))
Cells(X, "d") = Application.WorksheetFunction.Sum(Range([d5], Cells(X, "d")))
[A1].Select
Dim rCell As Range
Dim e As Integer
    For Each rCell In Range("l5:l5000")
        If UCase(rCell) = " " Then
        rCell.Select
        End If
    Next rCell
    e = ActiveCell.Row
  Sheets("DATA_FLDO").Range("a" & e & ":m" & e).Select
With Selection
.Font.Size = 22
.Font.Bold = True
.Font.Name = "Traditional Arabic"
.Font.Color = vbBlue
.Interior.Color = &HFFFFC0
.Borders.Weight = xlThick
.Borders.Weight = xlThisWeek
.Borders.Color = vbRed
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
End With
Cells(X, "a").Select
Application.EnableEvents = True
Application.ScreenUpdating = True
ListBox1.Clear
TextBox4.Text = ""
TextBox4.SetFocus
End Sub
Private Sub TextBox4_Change()
Application.ScreenUpdating = False
On Error Resume Next
Dim MYSH As Worksheet
Dim V As Integer, LastRow As Integer
Dim M As String
Dim q, F
ListBox1.Clear
Frame1.Visible = True
Frame2.Visible = True
Frame3.Visible = True
Frame4.Visible = True
Frame5.Visible = True
Frame6.Visible = True
Frame7.Visible = True
Frame8.Visible = True
Frame9.Visible = True
Frame10.Visible = True
Frame13.Visible = True
Labl_A.Visible = True
Label6.Visible = True
Label7.Visible = True
Label8.Visible = True
Label9.Visible = True
Label10.Visible = True
Label11.Visible = True
Label12.Visible = True
Label13.Visible = True
Label14.Visible = True
Label15.Visible = True
A_1.Visible = True
A_2.Visible = True
A_3.Visible = True
A_4.Visible = True
A_5.Visible = True
A_6.Visible = True
ListBox1.Visible = True
Text_A.Visible = True
TextBox1.Visible = True
TextBox2.Visible = True
TextBox3.Visible = True
TextBox5.Visible = True
TextBox6.Visible = True
TextBox7.Visible = True
TextBox8.Visible = True
TextBox9.Visible = True
TextBox10.Visible = True
TextBox11.Visible = True
If TextBox4 = "" Then
ListBox1.Visible = True
Frame1.Visible = False
Frame2.Visible = False
Frame3.Visible = False
Frame4.Visible = False
Frame5.Visible = False
Frame6.Visible = False
Frame7.Visible = False
Frame8.Visible = False
Frame9.Visible = False
Frame10.Visible = False
End If
M = TextBox4.Value
Set MYSH = Sheets("DATA_FLDO")
With MYSH
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
Set q = .Range("b5:b" & LastRow).Find(M)
If Not q Is Nothing Then
F = q.Address
Do
If Application.WorksheetFunction.Search(M, q, 1) = 1 Then
ListBox1.AddItem q.Value
ListBox1.List(V, 1) = q.Offset(0, -1).Text
ListBox1.List(V, 2) = q.Offset(0, 1).Text
ListBox1.List(V, 3) = q.Offset(0, 2).Text
ListBox1.List(V, 4) = q.Offset(0, 3).Text
ListBox1.List(V, 5) = q.Offset(0, 11).Text
ListBox1.List(V, 6) = q.Address
V = V + 1
End If
'Set q = .Range("c4:c" & LastRow).FindNext(q)
Loop While Not q Is Nothing And q.Address <> F
End If
End With
Application.ScreenUpdating = True
End Sub
Private Sub UserForm_Activate()
On Error Resume Next
     'Find the Excel main window
    mlHWnd = FindWindowA("XLMAIN", Application.Caption)
    FormHWnd = FindWindowA(vbNullString, Me.Caption)
    Call cmdTop_Click
     'Enable the Window - makes the userform modeless
    EnableWindow mlHWnd, 1
    mbDragDrop = Application.CellDragAndDrop
    Application.CellDragAndDrop = False
TextBox4 = ""
optHideTitleBar = True
Application.EnableEvents = False
Application.ScreenUpdating = False
CheckBox1 = False
optHideTitleBar.Visible = False
'===            
CommandButton1.Visible = False
CommandButton3.Visible = False
Labl_A.Visible = False
Label6.Visible = False
Label7.Visible = False
Label8.Visible = False
Label9.Visible = False
Label10.Visible = False
Label11.Visible = False
Label12.Visible = False
Label13.Visible = False
Label14.Visible = False
Label15.Visible = False
Frame1.Visible = False
Frame2.Visible = False
Frame3.Visible = False
Frame4.Visible = False
Frame5.Visible = False
Frame6.Visible = False
Frame7.Visible = False
Frame8.Visible = False
Frame9.Visible = False
Frame10.Visible = False
Frame13.Visible = False
Frame11.Visible = True

A_1.Visible = False
A_2.Visible = False
A_3.Visible = False
A_4.Visible = False
A_5.Visible = False
A_6.Visible = False
Text_A.Visible = False
TextBox1.Visible = False
ListBox1.Visible = False
TextBox2.Visible = False
TextBox3.Visible = False
TextBox5.Visible = False
TextBox6.Visible = False
TextBox7.Visible = False
TextBox8.Visible = False
TextBox9.Visible = False
TextBox10.Visible = False
TextBox11.Visible = False
TextBox5 = ""
'===           - 
A_1 = Cells(4, "a")
A_2 = Cells(4, "b")
A_3 = Cells(4, "c")
A_4 = Cells(4, "d")
A_5 = Cells(4, "e")
A_6 = Cells(4, "l")
Labl_A = Cells(4, "a")
Label6 = Cells(4, "b")
Label7 = Cells(4, "c")
Label8 = Cells(4, "d")
Label9 = Cells(4, "f")
Label10 = Cells(4, "g")
Label11 = Cells(4, "i")
Label12 = Cells(4, "k")
Label13 = Cells(4, "l")
Label14 = Cells(4, "m")
Label15 = Cells(4, "n")
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
Private Sub UserForm_Initialize()
Dim B As Boolean
B = IsTitleBarVisible(UF:=Me)
If B = True Then
    Me.lblCaptionVisible.Caption = ""
Else
    Me.lblCaptionVisible.Caption = ""
End If
End Sub
